<script>
import outMain from "@/components/outMain.vue";
import elSelect from "@/components/public/elSelect.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { Contract, contractDel } from "@/http/api";
export default {
  components: { outMain, elSelect },
  name: "",
  data() {
    return {
      tableData: [],
      statusArr: [
        { label: "全部", value: "" },
        { label: "待签约", value: "1" },
        { label: "已完成", value: "2" },
        { label: "已取消", value: "3" },
      ],
      queryData: {
        contract_signing_status: 3,
        contract_number: "",
        cjr_name: "",
        time: "",
        page: 1,
        per_page: 20,
      },
      total: 0,
    };
  },
  props: {},
  setup() {},
  methods: {
    detailFn(row) {
      this.$router.push({
        path: "/moneyBookDetail",
        query: { id: row.contract_id },
      });
    },
    getData() {
      let paramsData = { ...this.queryData };
      if (paramsData.time) {
        let start = this.$converData.getTime(paramsData.time[0]);
        let end = this.$converData.getTime(paramsData.time[1]);
        paramsData.time = start + "," + end;
      }
      Contract(paramsData).then((res) => {
        if (res.data.code == 1) {
          this.tableData = res.data.data.data;
          this.total = res.data.data.total;
        }
      });
    },
    deleteFn(row) {
      ElMessageBox.confirm(
        "确定删除选择的合同吗?一旦删除无法恢复，请谨慎操作！",
        "删除提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).then(async () => {
        const { data } = await contractDel({ contract_id: row.contract_id });
        if (data.code == 1) {
          ElMessage({
            type: "success",
            message: "删除成功",
          });
          this.getData();
        }
      });
    },
  },
  mounted() {},
  created() {
    this.getData();
  },
};
</script>
<template>
  <outMain>
    <div class="tableCont">
      <div class="tableName flexCont">
        <div>合同记录-已取消({{ total }})</div>
      </div>
      <div class="tableSerch">
        <div class="serchLeft"></div>
        <div class="serchRight">
          <el-form class="flexCenter" :inline="true">
            <el-form-item>
              <el-input
                v-model="queryData.contract_number"
                placeholder="请输入合同编号查询"
              />
            </el-form-item>
            <el-form-item>
              <el-input
                v-model="queryData.cjr_name"
                placeholder="请输入出借人姓名"
              />
            </el-form-item>
            <el-form-item v-if="false">
              <elSelect
                placeholder="请选择退款状态"
                v-model="queryData.contract_signing_status"
                :selectValue="queryData.contract_signing_status"
                :selectArr="statusArr"
              ></elSelect>
            </el-form-item>
            <el-form-item style="width: 320px">
              <el-date-picker
                v-model="queryData.time"
                style="width: 300px"
                type="daterange"
                range-separator="～"
                start-placeholder="起始时间"
                end-placeholder="截止时间"
              />
            </el-form-item>

            <btn value="搜索" @click="getData"></btn>
          </el-form>
        </div>
      </div>
      <el-table class="tableMain" :data="tableData" stripe style="width: 100%">
        <el-table-column
          show-overflow-tooltip
          prop="contract_number"
          label="合同编号"
          width="200"
        />
        <el-table-column
          prop="loan_money"
          show-overflow-tooltip
          label="借款金额"
        />
        <el-table-column
          prop="repayment_money"
          show-overflow-tooltip
          label="还款金额"
        />
        <el-table-column
          prop="loan_date"
          show-overflow-tooltip
          label="借款日期"
        />
        <el-table-column
          prop="repayment_date"
          show-overflow-tooltip
          label="借款日期"
        />
        <el-table-column
          prop="interest_rate"
          show-overflow-tooltip
          label="年化利率"
        />
        <el-table-column
          prop="pay_money"
          show-overflow-tooltip
          label="合同状态"
        >
          <template #default="{ row }">
            <div class="tableCtrl">
              <el-tag v-if="row.contract_signing_status === 1">待签约</el-tag>
              <el-tag type="success" v-if="row.contract_signing_status === 2"
                >已完成</el-tag
              >
              <el-tag type="info" v-if="row.contract_signing_status === 3"
                >已取消</el-tag
              >
            </div>
          </template>
        </el-table-column>

        <el-table-column
          prop="create_time"
          width="180"
          show-overflow-tooltip
          label="创建时间"
        />
        <el-table-column prop="Name" width="100" label="操作">
          <template #default="{ row }">
            <div class="tableCtrl">
              <div class="greenText ctrlText" @click="detailFn(row)">详情</div>
              <div class="redText ctrlText" @click="deleteFn(row)">删除</div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageCont">
        <el-pagination
          v-model:currentPage="queryData.page"
          v-model:page-size="queryData.per_page"
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
        />
      </div>
    </div>
  </outMain>
</template>
<style scoped lang="less"></style>
